﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using PdfCreative.Filters.ConvertToTransparent;

namespace PdfCreative.Filters.ConvertToTransparent.Tests
{
    /// <summary>
    /// The FilterTests class contains unit tests for the Filter class.
    /// </summary>
    [TestClass]
    public class FilterTests
    {
        // Test methods
        // ============
        #region Test methods
        /// <summary>
        /// Black should convert to a fully opaque black.
        /// </summary>
        [TestMethod]
        public void ShouldConvertBlacktoBlack()
        {
            var filter = new Filter();
            Assert.AreEqual((uint)(0xff000000), filter.Execute(0x0));
        }

        /// <summary>
        /// White should convert to a fully transparent black colour.
        /// </summary>
        [TestMethod]
        public void ShouldConvertWhiteToTransparent()
        {
            var filter = new Filter();
            var white =     (uint)(0xffffffff);
            var expected =  (uint)(0x00000000);
            Assert.AreEqual(expected, filter.Execute(white)); 
        }

        /// <summary>
        /// Grey tints should convert to semi-transparent black colours.
        /// </summary>
        [TestMethod]
        public void ShouldConvertGreyToTransparent()
        {
            var filter = new Filter();
            var light = (uint)(0x00aaaaaa);
            Assert.AreEqual((uint)(0x55000000), filter.Execute(light));

            var medium = (uint)(0x007f7f7f);
            Assert.AreEqual((uint)(0x80000000), filter.Execute(medium));

            var dark = (uint)(0x00555555);
            Assert.AreEqual((uint)(0xaa000000), filter.Execute(dark));

        }

        /// <summary>
        /// Primary (fully-saturated) colours should convert to fully opaque
        /// copies of themselves.
        /// </summary>
        [TestMethod]
        public void ShouldConvertPrimaryColours()
        {
            var filter = new Filter();

            var red = (uint)(0x00ff0000);
            Assert.AreEqual((uint)(0xffff0000), filter.Execute(red));

            var green = (uint)(0x0000ff00);
            Assert.AreEqual((uint)(0xff00ff00), filter.Execute(green));

            var yellow = (uint)(0x00ffff00);
            Assert.AreEqual((uint)(0xffffff00), filter.Execute(yellow));

            var blue = (uint)(0x000000ff);
            Assert.AreEqual((uint)(0xff0000ff), filter.Execute(blue));

            var magenta = (uint)(0x00ff00ff);
            Assert.AreEqual((uint)(0xffff00ff), filter.Execute(magenta));

            var cyan = (uint)(0x0000ffff);
            Assert.AreEqual((uint)(0xff00ffff), filter.Execute(cyan));

        }

        /// <summary>
        /// Tests conversion of colours. Two colours are selected for the
        /// test - purple and dark cyan (randomly picked).
        /// </summary>
        [TestMethod]
        public void ShouldConvertColour()
        {
            var filter = new Filter();

            var purplish = (uint)(0x00FFA8F9);
            Assert.AreEqual((uint)(0x57FF00ED), filter.Execute(purplish));

            var darkCyan = (uint)(0x00618C93);
            Assert.AreEqual((uint)(0x56007E93), filter.Execute(darkCyan));
        }
        #endregion
    }
}
